﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SDM.ExamPlanner.BLL;
using SDM.ExamPlanner.DTO;

namespace sdm.exam.ui.ExamAdministration
{
    /// <summary>
    /// Interaction logic for ExamPlanningList.xaml
    /// </summary>
    public partial class ExamPlanningList : UserControl
    {
        readonly Manager<SchoolClass> _schoolClassManager = new Manager<SchoolClass>();
        readonly Manager<Exam> _examManager = new Manager<Exam>();
        Dictionary<int, string> _schoolClassDictionary = new Dictionary<int, string>(); 
        Dictionary<int, string> _examsDictionary = new Dictionary<int, string>();
        public ExamPlanningList()
        {
            InitializeComponent();
            PopulateCombobox();
        }

        private void PopulateCombobox()
        {
            _schoolClassDictionary = _schoolClassManager.Find().ToDictionary(item => item.Id, item => item.Name);
            comboBoxSemester.DataContext = _schoolClassDictionary.Values;
        }

        private void comboBoxSemester_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedClass = (string) comboBoxSemester.SelectedValue;
            _examsDictionary =
                _examManager.Find().Where(ex => ex.SchoolClass.Name == selectedClass).ToDictionary(item => item.Id,
                                                                                                 item => item.Name);
            lstExams.DataContext = _examsDictionary.Values;
        }

    }
}
